<?php
namespace app\admin\controller;
use think\Controller;
use app\common\model;
use think\Hook;
class Login extends Controller{
    public function index(){
        $id = new \Auth;
        dump($id);die;
    	return $this->fetch();
    }

    public function dologin(){
    	$request = $this->request;
    	if(!$request->isPost() || !$request->isAjax()){
    		return;
    	}

    	$username = $request->post('username');
    	$password = $request->post('password');
    	if(empty($username)){
    	   return $this->error('请输入用户名');
    	}elseif(empty($password)){
    		return $this->error('请输入密码');
    	}
    	$model = new model\User();
    	$re = $model->where('username',$username)->find();
    	if(empty($re)){
    		return $this->error('用户名不正确');
    	}
        $password = sp_password($password,$re->salt);
		if($password != $re->password){
            return $this->error('密码不正确');
        }
        Hook::listen('admin_login_success');

        $this->success('登录成功');

    }

}